﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using OpenFlashChart;

namespace PeisongWeb.admin
{
    public partial class iframe_monthGPM : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                 RenderChart();
            }
        }

        private void RenderChart()
        {
            OpenFlashChart.OpenFlashChart chart = new OpenFlashChart.OpenFlashChart();

            int productId = 0;
            int.TryParse(Request.QueryString["productId"], out productId);

            if (productId != 0)
            {
                int year = DateTime.Now.Year;
                int.TryParse(ddlYear.SelectedValue, out year);

                DataSet ds = logic.product.productMonthGPMlistByProductAndYear(productId, year);
                string productName = ds.Tables[0].Rows[0]["name"].ToString();
                DataTable dt = ds.Tables[1];

                ArrayList data1 = new ArrayList();
                IList<string> weekLabels = new List<string>();

                foreach (DataRow row in dt.Rows)
                {
                    data1.Add(new LineDotValue(Convert.ToDouble(row["gpmRate"]), string.Format("{0}月毛利率{1:F2}%,当月总毛利{2:F2}元", row["month"], row["gpmRate"], row["gpm"]), "#fe0"));
                    weekLabels.Add(row["month"].ToString());
                }

                OpenFlashChart.LineHollow line1 = new LineHollow();
                line1.Values = data1;
                line1.HaloSize = 0;
                line1.Width = 2;
                line1.DotSize = 5;
                line1.Text = "商品月平均毛利率（百分比）";

                line1.Tooltip = "提示：#val#";

                chart.X_Axis.Labels.SetLabels(weekLabels);

                chart.AddElement(line1);

                chart.Title = new Title(string.Format("{0}{1}年月平均毛利率", productName, year));
                chart.Y_Axis.SetRange(-100, 100, 20);
                chart.Tooltip = new ToolTip("全局提示：#val#");
                chart.Tooltip.Shadow = true;
                chart.Tooltip.Colour = "#e43456";
                chart.Tooltip.MouseStyle = ToolTipStyle.CLOSEST;
                OpenFlashChartControl1.Visible = true;
                OpenFlashChartControl1.EnableCache = false;
                OpenFlashChartControl1.Chart = chart;
            }
            else
            {
                OpenFlashChartControl1.Visible = false;
            }
        }

        protected void btnAnalysis_Click(object sender, EventArgs e)
        {
            RenderChart();
        }
    }
}
